home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / zm16src.lzh / MAIN.C < prev    next >
C/C++ Source or Header  |  1988-05-19  |  13KB  |  700 lines

  1. /*
  2.  *     Main Module
  3.  *
  4.  *        Jwahar Bammi
  5.  *            usenet: mandrill!bammi@{decvax,sun}.UUCP
  6.  *            csnet:  bammi@mandrill.ces.CWRU.edu
  7.  *            arpa:   bammi@mandrill.ces.CWRU.edu
  8.  *            CompuServe: 71515,155
  9.  */
  10.  
  11. #include "config.h"
  12.  
  13. #include "zmdm.h"
  14. #include "common.h"
  15.  
  16. #ifndef Vsync             /* Atari forgot these in osbind.h */
  17. #define Vsync()    xbios(37)
  18. #endif
  19.  
  20. #define    esc    27
  21. #define cr    0x0d
  22. #define mvto(r,c)    EscSeq('Y');Bconout(2,r+040);Bconout(2,c+040)
  23.  
  24.  
  25.      /* Globals belonging to this module only */
  26.  
  27. int    rs232 = 1,        /* Ports */
  28.         console = 2;
  29. int    speed,              /* rs232 setup parameters */
  30. #ifdef FLOW_CTRL
  31.      flowctl = 1,
  32. #else
  33.     flowctl = 0,
  34. #endif
  35.     ucr = -1,
  36.     rsr = -1,
  37.     tsr = -1,
  38.     scr = -1;
  39.  
  40. /*
  41.  * setRs232() - set rs232 port configuration
  42.  */
  43. #ifndef REMOTE
  44. void setRs232 ()
  45. {
  46.     char ch;
  47.     long conin;
  48.     
  49.     Bconws("Baud rate: ");
  50.     EscSeq('p');
  51.     Bconws("0=19200 1=9600, 2=4800, 3=2400, 4=1200, 5=300\r\n");
  52.     EscSeq('q');
  53.     Bconout(2, '\t');
  54.     EscSeq('p');
  55.     Bconws("What speed==>");
  56.     EscSeq('q');
  57.     
  58.     conin = Bconin(console);    /* get speed */
  59.     if ((conin & 0x00FF0000L) == 0x00610000L)
  60.     {
  61.         his_screen();
  62.         ResetIoBuf();
  63.         finish();
  64.     }
  65.     ch = (char) (conin & 0x007f);
  66.     Bconout(2, ' ');
  67.     switch (ch)
  68.     {
  69.         case '0':        /* 19200 */
  70.         speed = 0;
  71.         Bconws("19200");
  72.         Baudrate = 19200;
  73.         break;
  74.         
  75.         case '1':
  76.         speed = 1;    /* 9600 */
  77.         Bconws("9600");
  78.         Baudrate = 9600;
  79.         break;
  80.         
  81.         case '2':
  82.         speed = 2;    /* 4800 */
  83.         Bconws("4800");
  84.         Baudrate = 4800;
  85.         break;
  86.         
  87.         case '3':
  88.         speed = 4;    /* 2400 */
  89.         Bconws("2400");
  90.         Baudrate = 2400;
  91.         break;
  92.         
  93.         case '4':
  94.         speed = 7;    /* 1200 */
  95.         Bconws("1200");
  96.         Baudrate = 1200;
  97.         break;
  98.         
  99.         case '5':
  100.         speed = 9;    /* 300 */
  101.         Bconws("300");
  102.         Baudrate = 300;
  103.         break;
  104.         
  105.         default:
  106.         speed = getbaud();
  107.         Bconws(BAUD_STRING(speed));
  108.         Baudrate = BAUD_RATE(speed);
  109.     }
  110.     Bconws(" Baud\r\n");
  111.     
  112.     /* Set new Baud rate */
  113.  
  114. /*    Txoff(); */
  115.     Rsconf(speed, flowctl, ucr, rsr, tsr, scr);
  116.     Vsync(); Vsync();
  117. /*    Txon(); */
  118.  
  119.     
  120. }
  121. #else
  122. void setRs232 ()
  123. {
  124.     char ch;
  125.     long conin;
  126.     
  127.     Bauxws("Baud rate: ");
  128.     Bauxws("0=19200 1=9600, 2=4800, 3=2400, 4=1200, 5=300\r\n");
  129.     Bconout(1, '\t');
  130.     Bauxws("What speed==>");
  131.     
  132.     conin = Bconin(1);    /* get speed */
  133.     if (((int)(conin & 0x007f) & CTRL('U')) == CTRL('U'))
  134.     {
  135.         his_screen();
  136.         ResetIoBuf();
  137.         finish();
  138.     }
  139.     ch = (char) (conin & 0x007f);
  140.     Bconout(1, ' ');
  141.     switch (ch)
  142.     {
  143.         case '0':        /* 19200 */
  144.         speed = 0;
  145.         Bauxws("19200");
  146.         Baudrate = 19200;
  147.         break;
  148.         
  149.         case '1':
  150.         speed = 1;    /* 9600 */
  151.         Bauxws("9600");
  152.         Baudrate = 9600;
  153.         break;
  154.         
  155.         case '2':
  156.         speed = 2;    /* 4800 */
  157.         Bauxws("4800");
  158.         Baudrate = 4800;
  159.         break;
  160.         
  161.         case '3':
  162.         speed = 4;    /* 2400 */
  163.         Bauxws("2400");
  164.         Baudrate = 2400;
  165.         break;
  166.         
  167.         case '4':
  168.         speed = 7;    /* 1200 */
  169.         Bauxws("1200");
  170.         Baudrate = 1200;
  171.         break;
  172.         
  173.         case '5':
  174.         speed = 9;    /* 300 */
  175.         Bauxws("300");
  176.         Baudrate = 300;
  177.         break;
  178.         
  179.         default:
  180.         speed = getbaud();
  181.         Bauxws(BAUD_STRING(speed));
  182.         Baudrate = BAUD_RATE(speed);
  183.     }
  184.     Bauxws(" Baud\r\n");
  185.     
  186.     /* Set new Baud rate */
  187.  
  188. /*    Txoff(); */
  189.     Rsconf(speed, flowctl, ucr, rsr, tsr, scr);
  190.     Vsync(); Vsync();
  191. /*    Txon(); */
  192.  
  193.     
  194. }
  195. #endif /* REMOTE */
  196.  
  197. /*
  198.  * help() - display help info and menu
  199.  */
  200. #ifndef REMOTE
  201. void help ()
  202. {
  203.     register long conin;
  204.     register int x;
  205.     extern char *r_filename();
  206.     
  207.     my_screen();        /* Switch to my screen memory */
  208.     EscSeq('v');        /* wrap at end of line */
  209.     EscSeq('E');        /* clear screen */
  210.     
  211.     mvto(2,25);
  212.     EscSeq('p');
  213.     Bconws("ZMDM Version ");
  214.     Bconws(ZMDMVERSION);
  215.     EscSeq('q');
  216.     EscSeq('p');
  217.     x = strlen(COMPILER);
  218.     x = (80 - x)/2;
  219.     mvto(3,x);
  220.     Bconws(COMPILER);
  221.     EscSeq('q');
  222.     mvto(5,25);
  223.     Bconws("ST Enthusiasts @ ces.CWRU.edu\r\n\n");
  224.  
  225.     /* Put up menu */
  226.     Bconws("\r\n\t");
  227.     EscSeq('p');        /* reverse video */
  228.     Bconws("Undo");
  229.     EscSeq('q');        /* quit reverse video */
  230.     Bconws(" to exit.\r\n");
  231.     
  232.     Bconws("\t");
  233.     EscSeq('p');        /* reverse video */
  234.     Bconws("Help");
  235.     EscSeq('q');        /* quit reverse video */
  236.     Bconws(" for this message.\r\n");
  237.  
  238.     Bconws("\t");
  239.     EscSeq('p');        /* reverse video */
  240.     Bconws("Escape");
  241.     EscSeq('q');        /* quit reverse video */
  242.     Bconws(" to send a break.\r\n");
  243.     
  244.     Bconws("\t");
  245.     EscSeq('p');        /* reverse video */
  246.     Bconws("T or t");
  247.     EscSeq('q');        /* quit reverse video */
  248.     Bconws(" to do file transfers and local functions.\r\n");
  249.  
  250. #ifdef PHONES
  251.     Bconws("\t");
  252.     EscSeq('p');        /* reverse video */
  253.     Bconws("P or p");
  254.     EscSeq('q');        /* quit reverse video */
  255.     Bconws(" for Phone services.\r\n");
  256. #endif
  257.  
  258.     if(rez == 2)
  259.     {
  260.         Bconws("\t");
  261.         EscSeq('p');        /* reverse video */
  262.         Bconws("H or h");
  263.         EscSeq('q');        /* quit reverse video */
  264.         Bconws(" for Hi Rez Toggle (25/50 Lines).\r\n");
  265.     }
  266.  
  267.     Bconws("\t");
  268.     EscSeq('p');        /* reverse video */
  269.     Bconws("I or i");
  270.     EscSeq('q');        /* quit reverse video */
  271.     Bconws(" to Invert screen colors.\r\n");
  272.     
  273.     Bconws("\t");
  274.     EscSeq('p');        /* reverse video */
  275.     Bconws("Return");
  276.     EscSeq('q');        /* quit reverse video */
  277.     Bconws(" to do nothing.\r\n");
  278.     
  279.     Bconws("\t");
  280.     EscSeq('p');        /* reverse video */
  281.     Bconws("B or b");
  282.     EscSeq('q');        /* quit reverse video */
  283.     Bconws(" to set baud rate.     Currently is ");
  284.     EscSeq('p');
  285.     Bconws(BAUD_STRING(speed));
  286.     Bconws(" Baud.\r\n\r\n");
  287.     EscSeq('q');
  288.  
  289.     /* get response */
  290.     conin = Bconin(console);
  291.  
  292.     if ((conin & 0x00FF0000L) == 0x00610000L)
  293.     {
  294.         /* He hit <UNDO> */
  295.         his_screen();
  296.         ResetIoBuf();
  297.         finish();
  298.     }
  299.     
  300.     switch((int)(conin & 0x007f))
  301.     {
  302.         case 'B':
  303.         case 'b':
  304.         /* Set baud rate */
  305.         setRs232();
  306.         break;
  307.         
  308.         case 'T':
  309.         case 't':
  310.             EscSeq('E');        /* clear screen */
  311.  
  312.             /* Set no flow Control */
  313. #ifdef FLOW_CTRL
  314.             Rsconf(-1,0,-1,-1,-1,-1);
  315.             Vsync(); Vsync();
  316.  
  317. #endif
  318.         /* Go do transfers */
  319.         transfer();
  320.             
  321. #ifdef FLOW_CTRL
  322.             /* Flow Control On */
  323. /*            Txoff(); */
  324.             Rsconf(-1,1,-1,-1,-1,-1);
  325.             Vsync(); Vsync();
  326. /*            Txon(); */
  327. #endif
  328.         his_screen();
  329.         return;
  330.         
  331.         case '\033':
  332.         /* Send a break */
  333.         sendbrk();
  334.         his_screen();    /* Don't wait for the key hit */
  335.  
  336.         return;
  337.  
  338.         case 'i':
  339.         case 'I':
  340.         /* Invert screen colors */
  341.         his_screen();
  342.         if(scolor == 0)
  343.         {
  344.             EscSeq('b');    /* Foreground color 0 */
  345.             Bconout(2, 0);
  346.             EscSeq('c');    /* Background color 1 */
  347.             Bconout(2, 1);
  348.             scolor = 1;
  349.         }
  350.         else
  351.         {
  352.             EscSeq('b');    /* Foreground color 1 */
  353.             Bconout(2, 1);
  354.             EscSeq('c');    /* Background color 0 */
  355.             Bconout(2, 0);
  356.             scolor = 0;
  357.         }
  358.         EscSeq('E');        /* Clear the screen */
  359.         return;
  360.  
  361. #ifdef PHONES
  362.         case 'p':
  363.         case 'P':
  364.         /* Phone Services */
  365.         phone();
  366.         return;
  367. #endif
  368.         case 'h':
  369.         case 'H':
  370.         /* Hi rez 25/50 toggle */
  371.         if(rez == 2)
  372.         {
  373.             if(hlines == 25)
  374.             {
  375.                 hlines = 50;
  376.                 hi50();
  377.             }
  378.             else
  379.             {
  380.                 hlines = 25;
  381.                 hi25();
  382.             }
  383.             his_screen();
  384.             EscSeq('E');        /* clear screen */
  385.             return;
  386.         }
  387.         /* else fall Through */
  388.         
  389.         default:
  390.         Bconws("No Change\r\n");
  391.     }
  392.  
  393.     /* Wait for a key hit */
  394.     hit_key();
  395.     /* back to terminal screen */
  396.     his_screen();
  397. }
  398. #else
  399. void help ()
  400. {
  401.     register long conin;
  402.     extern char *r_filename();
  403.     
  404.     my_screen();        /* Switch to my screen memory */
  405.     
  406.     Bauxws("\r\n\n");
  407.     Bauxws("                        RZMDM Version ");
  408.     Bauxws(ZMDMVERSION);
  409.     Bauxws("\r\n                         ");
  410.     Bauxws(COMPILER);
  411.     Bauxws("\r\n\n                        ST Enthusiasts @ ces.CWRU.edu\r\n\n");
  412.  
  413.     /* Put up menu */
  414.     Bauxws("\r\n\t");
  415.     Bauxws("CTRL-U");
  416.     Bauxws(" to exit.\r\n");
  417.     
  418.     Bauxws("\t");
  419.     Bauxws("CTRL-Z");
  420.     Bauxws(" for this message.\r\n");
  421.  
  422.     Bauxws("\t");
  423.     Bauxws("Escape");
  424.     Bauxws(" to send a break.\r\n");
  425.     
  426.     Bauxws("\t");
  427.     Bauxws("T or t");
  428.     Bauxws(" to do file transfers and local functions.\r\n");
  429.  
  430.     Bauxws("\t");
  431.     Bauxws("Return");
  432.     Bauxws(" to do nothing.\r\n");
  433.     
  434.     Bauxws("\t");
  435.     Bauxws("B or b");
  436.     Bauxws(" to set baud rate.     Curently is ");
  437.     Bauxws(BAUD_STRING(s